package by.ins.life.simpleimpl;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import by.ins.life.IData;
import by.ins.life.ILife;
import by.ins.life.ISet;
import by.ins.life.ISolver;
import by.ins.life.evolution.ILifeEvoluter;
import by.ins.life.impl.Set;
import by.ins.out.HTMLRenderer;
import by.ins.out.IRenderer;

public class Life<NuclearType> implements ILife<NuclearType>, Serializable {
	
	private static final long serialVersionUID = 1L;
	protected List<ISet<NuclearType>> history;
	private int initHistoryCapasity = 1000;
	protected int maxEvolutionCount = 100;
	private ISolver<NuclearType> solver;
	private ILifeEvoluter<NuclearType> lifeEvolutor;
	private transient IRenderer render;
	private ISet<NuclearType> set;
	private String name;

	public Life() {
		history = new ArrayList<ISet<NuclearType>>();
	//	this.init();
	}

	@Deprecated
	protected void init() {
		history = new ArrayList<ISet<NuclearType>>(initHistoryCapasity);

		try {
			render = new HTMLRenderer(new PrintWriter(new File("e:/out.html")));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Set<NuclearType> set = new Set<NuclearType>(10, 10);	
	}

	public ISet<NuclearType> getLastEvolutionSet() {
		if(history.isEmpty() ){
			return null;
		}
		return history.get(history.size() - 1);
	}

	public ISolver<NuclearType> getSolver() {
		return solver;
	}

	public void setSolver(ISolver<NuclearType> iSolver) {
		this.solver = iSolver;
	}

	public ILifeEvoluter<NuclearType> getLifeEvolutor() {
		return lifeEvolutor;
	}

	public IRenderer getRender() {
		return render;
	}

	public void setRender(IRenderer render) {
		this.render = render;
	}

	public ISet<NuclearType> getSet() {
		return set;
	}

	public void setSet(ISet<NuclearType> set) {
		this.set = set;
	}

	public void setLifeEvolutor(ILifeEvoluter<NuclearType> lifeEvolutor) {
		this.lifeEvolutor = lifeEvolutor;
	}

	@Override
	public int getCurrentEvilutionIndex() {
		// TODO Auto-generated method stub
		return 0;
	}

	
	@Override
	public Map<IData<NuclearType>, IData<NuclearType>>  getHistorySolution(long solver, long set) {
		// TODO Auto-generated method stub
		return null;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public List<ISet<NuclearType>> getSetHistory() {
		// TODO Auto-generated method stub
		return null;
	}

	/*@Override
	public void setInitializer(ILifeInitializer lifeInitializer) {
		// TODO Auto-generated method stub
		
	}
*/
	
	@Override
	public String toString(){		
		StringBuilder sb = new StringBuilder();
		sb.append("");
		
		return sb.toString();
	}

}
